package com.tree.xinhe.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.tree.xinhe.R;
import com.tree.xinhe.entity.AdImg;

import java.util.List;

/**
 * Created by tree on 2016/12/29.
 */

public class ListAdapter extends BaseAdapter {
    private Context ctx;
    private List<AdImg> list;

    public ListAdapter(Context ctx, List<AdImg> list) {
        this.ctx = ctx;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView==null){
            convertView = LayoutInflater.from(ctx).inflate(R.layout.adapter_list,null,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        String imgUrl = "http://120.27.97.93:8080/xhsc"+list.get(position).getImgUrl();
        Glide.with(ctx).load(imgUrl).into(holder.img);
        return convertView;
    }

    static class ViewHolder{
        ImageView img;
        public ViewHolder(View v){
            img = (ImageView) v.findViewById(R.id.img);
        }
    }
}
